export default {
  namespaced: true,

  state: {
    token: uni.getStorageSync('token') || '',

    address: uni.getStorageSync('address')
      ? JSON.parse(uni.getStorageSync('address'))
      : {},

    userinfo: uni.getStorageSync('userinfo')
      ? JSON.parse(uni.getStorageSync('userinfo'))
      : {},
  },

  getters: {
    fullAddress(state) {
      const { provinceName, cityName, countyName, detailInfo } = state.address

      if (!provinceName) return ''

      return provinceName + cityName + countyName + detailInfo
    },
  },

  mutations: {
    setAddress(state, address) {
      state.address = address

      uni.setStorageSync('address', JSON.stringify(state.address))
    },

    // 更新用户的基本信息
    updateUserInfo(state, userinfo) {
      state.userinfo = userinfo

      // 持久化到本地缓存
      uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
    },

    setToken(state, token) {
      // Bearer 前缀拼好了
      state.token = token

      uni.setStorageSync('token', token)

      // console.log('用户仓库中的数据们', state)
    }
  },

  actions: {},
}
